#ifndef __PAGE_H_
#define __PAGE_H_

#include <globalDecl.h>
#include <record.h>
#include <schema.h>


class Page 
{
	// use whatever container stuff you want here; basically, you need
	// to choose some data structure (like a linked list) that allows you
	// to manange a set of Record objects
	
	int m_iPageSize;	
	int m_iBytesInPage; // bytes that we have stored in page
	int m_iCurrRecPtr;  // pointes to the current record offset from the start of the page. ie do m_cPage + m_iCurrRecPtr to go to the record.
	//char* m_cPage; // this holds flat binary page in mem
	list<Record> m_lRecordList; // this is our data structure to hold records.

public:
	// this is the constructor; the arg tells the page how many bytes it
	// is allowed to store
	Page (int maxSizeInBytes);
	~Page ();

	// this takes a page and writes its binary representation to bits
	int ToBinary (char *bits);

	// this takes a binary representation of a page and gets the
	// records from it
	int FromBinary (char *bits);

	// the deletes the first record from a page and returns it; returns
	// a zero if there were no records on the page
	int GetFirst (Record &firstOne);

	// this appends the record to the end of a page.  The return value
	// is a one on success and a zero if there is no more space.
	// Note that the record is consumed so it will have no value after
	int Append (Record &addMe);

	// empty out the page so that it contains no records
	void EmptyItOut ();

	void Test (Schema&,FILE*);

	int GetRecordCount();
};

#endif
